<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/12
 * Time: 10:23
 */

namespace app\common\service;


class NormalRuleGroup
{
    /**
     * @name 列表
     * @param $hostId
     * @param $params
     * @param $limit
     * @return array
     * @author wx
     * @date 2019/11/12 10:58
     */
    function list($hostId, $params, $limit)
    {
        $server = db('ips_normal_rule_group')->alias('nrg')
            ->field('nrg.id, nrg.name, nrg.description, hnrgr.status, hnrgr.total, hnrgr.used, hnrgr.handle')
            ->join('host_normal_rule_group_relation hnrgr', 'hnrgr.group_id = nrg.id')
            ->where('host_id', $hostId);

        !isset($params['name']) || empty($params['name']) ? : $server->whereLike('name', '%'. $params['name'] . '%');
        !isset($params['description']) || empty($params['description']) ? : $server->whereLike('description', '%'. $params['description'] . '%');
        !isset($params['status']) || !is_numeric($params['status']) ? : $server->where('hnrgr.status', $params['status']);
        $data = $server->paginate($limit)->toArray();

        return $data;
    }
}